package com.ruoyi.logistic.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.logistic.domain.NetworkExportConfiguration;
import com.ruoyi.logistic.domain.PageDate;
import com.ruoyi.logistic.domain.PageInfo;
import com.ruoyi.logistic.domain.vo.NetworkExportConfigurationSearchVo;
import com.ruoyi.logistic.service.INetworkExportConfigurationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/network/export")
@RestController
@Api(tags = "网点财务_出港自动导出配置")
public class NetworkExportConfigurationController {
    @Autowired
    private INetworkExportConfigurationService networkExportConfigurationService;

    @ApiOperation("显示出港自动导出配置列表")
    @GetMapping("/selectAll")
    public R selectNetworkExportConfigurationAll(PageDate pageDate){
        List<NetworkExportConfiguration> networkOutboundSettlements = networkExportConfigurationService.selectAll(pageDate);
        if (networkOutboundSettlements == null || networkOutboundSettlements.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(PageInfo.info(networkOutboundSettlements));
        }
    }
    @ApiOperation("添加出港自动导出配置")
    @PostMapping("/insert")
    public R insertNetworkExportConfiguration(@RequestBody NetworkExportConfiguration networkExportConfiguration){
        Boolean isAdd = networkExportConfigurationService.insert(networkExportConfiguration);
        if (isAdd){
            return R.ok("添加成功");
        }else {
            return R.fail("添加失败");
        }
    }
    @ApiOperation("修改出港自动导出配置")
    @PostMapping("/update")
    public R updateNetworkExportConfiguration(@RequestBody NetworkExportConfiguration networkExportConfiguration){
        Boolean isUpdate = networkExportConfigurationService.update(networkExportConfiguration);
        if (isUpdate){
            return R.ok("修改成功");
        }else {
            return R.fail("修改失败");
        }
    }
    @ApiOperation("批量删除")
    @PostMapping("/deleteByIds")
    public R deleteNetworkOutboundSettlementByIds(@RequestParam("ids") List<Integer> ids){
        Integer count = networkExportConfigurationService.deleteByIds(ids);
        if (count > 0){
            return R.ok("批量删除成功");
        }else {
            return R.fail("批量删除失败");
        }
    }
    @ApiOperation("搜索出港自动导出配置")
    @PostMapping("/search")
    @ResponseBody
    public R search(@RequestBody NetworkExportConfigurationSearchVo networkExportConfigurationSearchVo) {
        List<NetworkExportConfiguration> networkExportConfigurations = networkExportConfigurationService.search(networkExportConfigurationSearchVo);
        if (networkExportConfigurations == null || networkExportConfigurations.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(PageInfo.info(networkExportConfigurations));
        }
    }
}
